package com.androidhive.androidlistview;

import java.util.HashMap;

//import com.androidhive.sessions.SecondActivity;
//import com.androidhive.sessions.SessionManager;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class SecondActivity extends Activity {
	SessionManager session;
EditText txtUsername, txtPassword;
	
	// login button
	Button btnLogin;
	
	// Alert Dialog Manager
	AlertDialogManager alert = new AlertDialogManager();
	
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_second); 
    }
	public void sendMessage(View view) {
        txtUsername = (EditText) findViewById(R.id.txtUsername);
        txtPassword = (EditText) findViewById(R.id.txtPassword); 
        
  
				// Get username, password from EditText
				String username = txtUsername.getText().toString();
				String password = txtPassword.getText().toString();
				
				// Check if username, password is filled				
				 Intent intent = getIntent();
				    String CropIdnew = intent.getStringExtra(MyWebViewClient.cropId);
				  //  session.logoutUser();
				    session.createLoginSessionCropId(CropIdnew);
				    HashMap<String, String> user = session.getUserDetails();
			      
			        String VendorId = (user.get(SessionManager.Vendor_Id)); 
			        String CropId = user.get(SessionManager.Crop_Id);
			        Log.d("VendorHK:",VendorId);
			        Log.d("Crop:HK",CropId );
			        
					
					// Check if username, password is filled				
					if(username.trim().length() > 0 && password.trim().length() > 0){
						// For testing puspose username, password is checked with sample data
						// username = test
						// password = test
						if(username.equals("test") && password.equals("test")){
							
							// Creating user login session
							// For testing i am stroing name, email as follow
							// Use user real data
//							session.createLoginSession("Android Hive", "anroidhive@gmail.com");
//							
//							// Staring MainActivity
//							Intent i = new Intent(getApplicationContext(), MainActivity.class);
//							startActivity(i);
//							finish();
							
						}else{
							// username / password doesn't match
							//alert.showAlertDialog(SecondActivity.this, "Login failed..", "Username/Password is incorrect", false);
						}				
					}else{
						// user didn't entered username or password
						// Show alert asking him to enter the details
						//alert.showAlertDialog(SecondActivity.this, "Login failed..", "Please enter username and password", false);
					}
					
				}
			
				
			}
		

